package com.efast.dmom.aps.datahandlers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.aps.bean.PlanOrder;
import com.efast.dmom.aps.entity.PlanOrderEntity;
import com.efast.dmom.aps.entity.PlanOrderScheduleInfoEntity;

/**
 * @author Aaron Liu
 *
 * @date:2020年2月10日
 */
@Component
public class PlanScheduleDataHandler {
	
	@Autowired
	private PlanOrderScheduleInfoDataHandler planOrderScheduleInfoDataHandler = null;
	
	@Autowired
	private ProductionLineDataHandler productionLineDataHandler;
	
	@Autowired
	private PlanOrderDataHandler planOrderDataHandler;
	
	@Autowired
	private RouteStepWCRelDataHandler routeStepWCRelDataHandler;
	
	@Autowired
	private RouteProdLineRelDataHandler routeProdLineRelDataHandler;
	

	public PlanScheduleDataHandler() {
		// TODO Auto-generated constructor stub
	}

	public List<PlanOrder> getUnbroadcastPlanOrder(long prodLineId) {
		return planOrderDataHandler.getUnbroadcastPlanOrders(prodLineId);
	}
	
	public void setPlantShopId(PlanOrderEntity orderEntity){
		
		planOrderDataHandler.setPlantShopId(orderEntity);
	}
	
	public void saveScheduledInfo(List<PlanOrderScheduleInfoEntity> infoList){
		
		// 1, delete all scheduled information accroding to scheduleDate
		planOrderScheduleInfoDataHandler.deteleByScheduleDate(infoList);
		
		planOrderScheduleInfoDataHandler.saveScheduledInfo(infoList);
	}
	
	public void savePlanOrderInfo(List<PlanOrder> orderList){
		//save 
		planOrderDataHandler.updatePlanOrder(orderList);;
	}
	
	public int getProdLineCapacity(long pLineKey) {

		return productionLineDataHandler.getProdLineCapacity(pLineKey);
	}
	
	public double getProdLineCapacity(long routeKey, long pLineKey){
		//aps_route_step_wc_rel,  
		// fetch the minimum capacity from the result set
		double minCapacity = routeStepWCRelDataHandler.getProdLineCapacity(routeKey,pLineKey);
		return minCapacity;
	}
	
	public long getDefaultProdLineKey(long routeKey){
		//aps_route_line_rel
		return routeProdLineRelDataHandler.getDefaultProdLineKey(routeKey);
	}

}
